<?php

namespace app\model;

use app\util\Tools;

class UserProgram extends Base
{
    protected $autoWriteTimestamp = true;
    protected $resultSetType = 'collection';
    protected $updateTime = 'updataTime';
    protected $createTime = 'addTime';

    static $yearVipMap = [0=>'普通会员', 1 => '年卡会员', 2=> '白金会员'];
    static $freshLevelMap = [0=>'普通会员', 1 => '团长', 2=> '高级团长'];
    static $freshAgentLevelMap = [0=> '普通', 1=> '省级', 2=> '市级', 3=> '区级',4=> '乡镇级'];

    public function user(){
        return $this->hasOne('User','userID','userID');
    }

    public function getVIPAttr($value){
        $vip = ['0' => '普通用户','1' => '会员'];
        return $vip[$value];
    }

    public function getYearVipTextAttr($value, $data){
        return self::$yearVipMap[$data['yearVip']];
    }

    public function getfreshLevelTextAttr($value, $data){
        return self::$freshLevelMap[$data['freshLevel']];
    }

    public function getagentAddTimeTextAttr($value, $data){
        return $data['agentAddTime'] ? date("Y-m-d H:i:s", $data['agentAddTime']) : '';
    }

    public function getBeansAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setBeansAttr($value){
        return $value * 100;
    }

    public function getcashbackAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setcashbackAttr($value){
        return $value * 100;
    }

    public function getallcashbackAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setallcashbackAttr($value){
        return $value * 100;
    }

    public function getFrostBeansAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setFrostBeansAttr($value){
        return $value * 100;
    }


    public function getAllMoneyAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setAllMoneyAttr($value){
        return $value * 100;
    }

    public function getfreshMoneyAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setfreshMoneyAttr($value){
        return $value * 100;
    }

    public function getintegralAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setintegralAttr($value){
        return $value * 100;
    }

    public function getintegralTotalAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setintegralTotalAttr($value){
        return $value * 100;
    }

    public function getGroupMoneyAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setGroupMoneyAttr($value){
        return $value * 100;
    }

    public function getGambleMoneyAttr($value){
        return Tools::bcCalculate($value, 100, '/');
    }

    public function setGambleMoneyAttr($value){
        return $value * 100;
    }
}
